package summary;

import java.util.LinkedList;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/10 15:15
 * https://leetcode-cn.com/problems/implement-stack-using-queues/
 */
public class Title225 {

    /**
     * 倒序存储
     */
    LinkedList<Integer> list;

    /**
     * 辅助队列：将listTemp的值赋值给list
     */
    LinkedList<Integer> listTemp;

    public Title225() {
        list = new LinkedList<>();
        listTemp = new LinkedList<>();
    }

    public void push(int x) {
        listTemp.offer(x);
        while (!list.isEmpty()) {
            listTemp.offer(list.poll());
        }
        LinkedList<Integer> temp = list;
        list = listTemp;
        listTemp = temp;
    }

    public int pop() {
        return list.poll();
    }

    public int top() {
        return list.peek();
    }

    public boolean empty() {
        return list.isEmpty();
    }

    public static void main(String[] args) {

    }
}
